

from ..models import Model


class PurchaseOrderLine(Model):
    _name = 'purchase.order.line'

    _metadata = {
        "context": {},
        "fieldsForSearch": {
            "name": None,
            "product_id": None,
            "product_uom_qty": None,
            "product_uom": None,

            "price_unit": None,
            "price_subtotal": None,
            "price_total": None,

        },
        "fieldsForBrowse": {
            "name": None,
            "product_id": None,
            "product_uom_qty": None,
            "product_uom": None,

            "price_unit": None,
            "price_subtotal": None,
            "price_total": None,

            "state": None,
            "invoice_status": None,

            "qty_to_deliver": None,
            "qty_delivered": None,
            "qty_delivered_manual": None,
            "qty_delivered_method": None,
            "company_id": None


            # "scheduled_date": None,
            # "qty_invoiced": None,
            # "qty_to_invoice": None,
            # "discount": None,


            # "sequence": None,
            # "display_type": None,
            # "product_uom_category_id": None,
            # "product_updatable": None,
            # "product_template_id": None,
            # "analytic_tag_ids": None,
            # "route_id": None,
            # "product_type": None,
            # "virtual_available_at_date": None,
            # "qty_available_today": None,
            # "free_qty_today": None,
            # "warehouse_id": None,
            # "is_mto": None,
            # "display_qty_widget": None,
            # "customer_lead": None,
            # "product_packaging": None,
            # "tax_id": None,
            # "currency_id": None,
            # "price_tax": None,

        },


        "field_onchange": {
            "name": "",
            "product_id": "1",
            "product_uom_qty": "1",
            "product_uom": "1",
            "price_unit": "1",
            "price_subtotal": "",
            "price_total": "1",
            "state": "1",
            "invoice_status": "1",
            "product_uom_category_id": "",
            "sequence": "",
            "display_type": "",
            "product_updatable": "",
            "product_template_id": "",
            "analytic_tag_ids": "",
            "route_id": "1",
            "product_type": "",
            "virtual_available_at_date": "",
            "qty_available_today": "",
            "free_qty_today": "",
            "scheduled_date": "",
            "warehouse_id": "",
            "qty_to_deliver": "",
            "is_mto": "",
            "display_qty_widget": "",
            "qty_delivered": "1",
            "qty_delivered_manual": "1",
            "qty_delivered_method": "1",
            "qty_invoiced": "1",
            "qty_to_invoice": "1",
            "customer_lead": "1",
            "product_packaging": "1",
            "tax_id": "1",
            "discount": "1",
            "currency_id": "",
            "price_tax": "",
            "company_id": ""
        },

        "columnsForPage": {
            "product_id": {"type": 'select',  "label": '产品', }

        }

    }

    def get_globals_dict(self, values, globals_dict=None):
        # to be override, to set globals_dict
        if not globals_dict:
            globals_dict = {}

        globals_dict.update({"company_id": values['order_id']['company_id']})
        return globals_dict


class PurchaseOrder(Model):
    _name = 'purchase.order'

    _metadata = {

        "context": {},

        "fieldsForSearch": {
            "state": None,
            "name": None,
            "partner_id": None,
            "company_id": None,
            "order_line": None,
            "user_id": None,
            "reference": None,
            "note": None,
            "date_order": None,

            # "validity_date": None,
            # "payment_term_id": None,
            # "amount_untaxed": None,
            # "amount_tax": None,
            # "amount_total": None,

            # "team_id": None,
            # "client_order_ref": None,
            # "fiscal_position_id": None,
            # "analytic_account_id": None,
            # "invoice_status": None,
            # "commitment_date": None,
        },

        "fieldsForBrowse": {
            "state": None,
            "name": None,
            "partner_id": None,

            "validity_date": None,
            "date_order": None,
            "payment_term_id": None,
            "order_line": None,
            "note": None,
            "amount_untaxed": None,
            "amount_tax": None,
            "amount_total": None,
            "user_id": None,
            "team_id": None,
            "company_id": None,
            "reference": None,
            "client_order_ref": None,
            "fiscal_position_id": None,
            "analytic_account_id": None,
            "invoice_status": None,
            "commitment_date": None,

            "pricelist_id": None,
            "currency_id": None,


            # "delivery_count": None,
            # "invoice_count": None,


            # "authorized_transaction_ids": None,
            # "picking_ids": None,

            # "sale_order_template_id": None,

            # "sale_order_option_ids": None,
            # "require_signature": None,
            # "require_payment": None,
            # "warehouse_id": None,
            # "incoterm": None,
            # "picking_policy": None,
            # "expected_date": None,
            # "effective_date": None,
            # "origin": None,
            # "campaign_id": None,
            # "medium_id": None,
            # "source_id": None,
            # "signed_by": None,
            # "signed_on": None,
            # "signature": None,
        },

        "field_onchange": {
            "authorized_transaction_ids": "",
            "state": "1",
            "picking_ids": "1",
            "delivery_count": "",
            "invoice_count": "",
            "name": "",
            "partner_id": "1",
            "partner_invoice_id": "",
            "partner_shipping_id": "1",
            "sale_order_template_id": "1",
            "validity_date": "",
            "date_order": "1",
            "pricelist_id": "1",
            "currency_id": "1",
            "payment_term_id": "",
            "order_line": "1",
            "order_line.display_type": "",
            "order_line.sequence": "",
            "order_line.product_uom_category_id": "",
            "order_line.product_updatable": "",
            "order_line.product_id": "1",
            "order_line.invoice_status": "1",
            "order_line.qty_to_invoice": "1",
            "order_line.qty_delivered_manual": "1",
            "order_line.qty_delivered_method": "1",
            "order_line.price_total": "1",
            "order_line.price_tax": "",
            "order_line.price_subtotal": "",
            "order_line.product_uom_qty": "1",
            "order_line.product_uom": "1",
            "order_line.qty_delivered": "1",
            "order_line.qty_invoiced": "1",
            "order_line.product_packaging": "1",
            "order_line.price_unit": "1",
            "order_line.tax_id": "1",
            "order_line.discount": "1",
            "order_line.customer_lead": "1",
            "order_line.route_id": "1",
            "order_line.analytic_tag_ids": "",
            "order_line.name": "",
            "order_line.invoice_lines": "1",
            "order_line.state": "1",
            "order_line.company_id": "",
            "order_line.product_template_id": "",
            "order_line.product_type": "",
            "order_line.virtual_available_at_date": "",
            "order_line.qty_available_today": "",
            "order_line.free_qty_today": "",
            "order_line.scheduled_date": "",
            "order_line.warehouse_id": "",
            "order_line.qty_to_deliver": "",
            "order_line.is_mto": "",
            "order_line.display_qty_widget": "",
            "order_line.currency_id": "",
            "note": "",
            "amount_untaxed": "",
            "amount_tax": "",
            "amount_total": "",
            "sale_order_option_ids": "",
            "sale_order_option_ids.product_id": "1",
            "sale_order_option_ids.name": "",
            "sale_order_option_ids.quantity": "",
            "sale_order_option_ids.product_uom_category_id": "",
            "sale_order_option_ids.uom_id": "1",
            "sale_order_option_ids.price_unit": "",
            "sale_order_option_ids.discount": "",
            "sale_order_option_ids.is_present": "",
            "sale_order_option_ids.sequence": "",
            "user_id": "1",
            "team_id": "1",
            "company_id": "1",
            "require_signature": "",
            "require_payment": "",
            "reference": "",
            "client_order_ref": "",
            "fiscal_position_id": "1",
            "analytic_account_id": "",
            "invoice_status": "",
            "warehouse_id": "1",
            "incoterm": "",
            "picking_policy": "1",
            "commitment_date": "1",
            "expected_date": "",
            "effective_date": "",
            "origin": "",
            "campaign_id": "",
            "medium_id": "",
            "source_id": "",
            "signed_by": "",
            "signed_on": "",
            "signature": "",
            "__last_update": "",
            "message_follower_ids": "",
            "activity_ids": "",
            "message_ids": "",
            "message_attachment_count": ""
        },

        "columnsForPage": {
            "order_line": {
                "type": 'table',
                "odooModel": 'sale.order.line',  # browse 用这个做二次查询
                "label": '明细',
                "vuxModel": 'saleOrderLine',  # viewO2m, formO2m 需要这个去找模型
                "refName": 'order_id'  # viewO2m, formO2m 需要这个补充 onchange 的 values
            }

        }




    }
